package com.propertree.mailer.helper;

import java.util.Date;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.propertree.mailer.bean.EMailPartyInfo;
import com.propertree.mailer.bean.EmailAttributes;

public class MessageDecorator {

	public static Message createMessage(Session session, EMailPartyInfo senderParty,
			EMailPartyInfo receiverParty, EmailAttributes email) {
		Message message = new MimeMessage(session);
		try {
			message.setFrom(new InternetAddress(senderParty.getEmailId()));
			message.setRecipients(Message.RecipientType.TO,
					InternetAddress.parse(receiverParty.getEmailId()));

			message.setSubject(email.getSubject());
			message.setContent(email.getBody(), "text/html");
			message.setSentDate(new Date());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return message;
	}
}
